package com.szh.mysobproject.ui.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.szh.mysobproject.databinding.SlideRcItemBinding
import com.szh.mysobproject.util.simpleToast

class SlideRcAdapter : RecyclerView.Adapter<SlideRcAdapter.SlideRcViewHolder>() {

    private val demos: ArrayList<String> = arrayListOf()

    @SuppressLint("NotifyDataSetChanged")
    fun setData(data: ArrayList<String>) {
        demos.clear()
        demos.addAll(data)
        notifyDataSetChanged()
    }

    class SlideRcViewHolder(val binding: SlideRcItemBinding) :
        RecyclerView.ViewHolder(binding.root) {
        fun binding(item: String, position: Int) {
            binding.tvSlide.text = item
            binding.tvSlide.setOnClickListener {
                simpleToast("demo$position")
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SlideRcViewHolder {
        val binding = SlideRcItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return SlideRcViewHolder(binding)
    }

    override fun onBindViewHolder(holder: SlideRcViewHolder, position: Int) {
        val item = demos[position]
        holder.binding(item, position)
    }

    override fun getItemCount(): Int = demos.size
}